package com.esint;

import redis.clients.jedis.Jedis;

import java.util.Set;

/**
 * @description: redis键测试类
 * @author: 谷明
 * @createDate: 2021/8/11 23:43
 */
public class TestKey {
    public static void main(String[] args) {
        Jedis jedis = new Jedis("192.168.43.166", 6379);

        System.out.println("清空数据："+jedis.flushDB());
        System.out.println("判断某个键是否存在："+jedis.exists("username"));
        System.out.println("新增<username, xiante>的键值对"+jedis.set("username", "xiante"));
        System.out.println("新增<passwd, passwd>的键值对"+jedis.set("passwd", "Password01!"));
        System.out.println("系统中所有的键如下：");
        Set<String> keys = jedis.keys("*");
        System.out.println(keys);

        System.out.println("删除键passwd：" + jedis.del("passwd"));
        System.out.println("判断键passwd是否存在："+ jedis.exists("passwd"));
        System.out.println("查看键username所存储的值的类型："+ jedis.type("username"));
        System.out.println("随机返回key空间的一个："+jedis.randomKey());
        System.out.println("重命名key："+ jedis.rename("username", "newname"));
        System.out.println("获取修改后key的："+jedis.get("newname"));
        System.out.println("按索引查询："+jedis.select(0));
        System.out.println("删除当前选择数据库中所有key："+ jedis.flushDB());
        System.out.println("返回当前数据库中key的数目："+jedis.dbSize());
        System.out.println("删除所有数据库中的所有key："+jedis.flushAll());
    }
}
